const path = require("path");
function resolve(dir) {
    return path.join(__dirname, dir)
}

console.log(process.env.VUE_APP_CURRENTMODE);


module.exports = {
    publicPath: './',
    outputDir: 'build',
    lintOnSave: false,
    productionSourceMap: false,
    configureWebpack: config => {
        config.entry.app = ["babel-polyfill", "./src/main.ts"];
        config.module.rules.push({
            test: /\.mjs$/,
            include: /node_modules/,
            type: 'javascript/auto'
        });
    },
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
        const types = ['vue-modules', 'vue', 'normal-modules', 'normal']

        config.module
            .rule('thejs')
            .test(/\.js$/)
            .include.add(path.resolve('src'))
            .add(path.resolve('node_modules/element-ui/packages'))
            .end()
            .use('babel-loader')
            .loader('babel-loader')
            .end()
        config.module
            .rule('vue')
            .use('vue-loader')
            .tap(args => {
                // 防止空白标签被过滤掉
                args.compilerOptions.whitespace = 'preserve'
            })
        config
            .plugin('html')
            .tap(args => {
                args[0].title = "环亚智慧安防系统"
                return args
            })
        if (process.env.VUE_APP_CURRENTMODE !== 'dev') {
            config.output.filename('js/[name].[contenthash].js');
            config.output.chunkFilename('js/[name].[contenthash].js');
        }

    },
    css: {
        // 是否使用css分离插件 ExtractTextPlugin
        extract: process.env.VUE_APP_CURRENTMODE === 'prod' ? true : false,
        // 开启 CSS source maps?
        sourceMap: process.env.VUE_APP_CURRENTMODE === 'prod' ? false : true,
        // css预设器配置项
        loaderOptions: {
            sass: {
                additionalData: `
                @import "@/assets/sass/mixin.scss";
                @import "@/assets/sass/var.scss";
                `
            }
        },
        // 启用 CSS modules for all css / pre-processor files.
        modules: false,
    },
    devServer: {
        port: 3300,
        proxy: {
            '/': {
                // target: `${process.env.VUE_APP_BASEURL}`
                target: "http://admin.park.hy-access.com/dist/"
                // logLevel: 'debug'
            }
        }
    }
}